package edu.ustb.spring.test;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.log4j.Logger;

/**
 * 环绕通知
 * @author lijia
 *
 */
public class LogAroundAdvice implements MethodInterceptor {

	Logger logger = Logger.getLogger(LogAroundAdvice.class);
	
	@Override
	public Object invoke(MethodInvocation invocation) throws Throwable {
		long beginTime = System.currentTimeMillis();
		invocation.proceed();
		long endTime = System.currentTimeMillis();
		String className = invocation.getClass().getName();
		String methodName = invocation.getMethod().getName();
		String message = "环绕通知："+className+" 类的 " + methodName +"" +
				" 方法执行了，执行时间= "+(endTime-beginTime)+" 毫秒";
		logger.info(message);
		return null;
	}

}
